#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>

#define SHM_KEY	123456557
#define SEM_KEY	456123462

int main()
{
	int *consoleBuffer;
	
	int shmid;
	if((shmid = shmget(SHM_KEY, sizeof(char), 0)) == -1)
	{
		perror("Error on shmget()\n");
		exit(-1);
	}
	
	if((consoleBuffer = (int *) shmat(shmid, NULL, 0)) == -1)
	{
		perror("Error on shmat(): \n");
		exit(-1);
	}
	
	int semid;
	if((semid = semget(SEM_KEY, 1, 0)) == -1)
	{
		printf("Error on semget()\n");
		exit(-1);
	}
	
	struct sembuf sops;
	sops.sem_num = 0;
	sops.sem_op = -1;
	sops.sem_flg = 0;
	
	while(1)
	{	
		if(semop(semid, &sops, 1) == -1)
		{
			perror("Error on semop()\n");
			exit(-1);
		}
		
		*consoleBuffer = -1;
		printf("Process line: ");
		scanf("%d", consoleBuffer);
		printf("Loading process...\n");
	}
}
		
		
